package com.zxlspace.thread;

public class YieldDemo01 extends Thread {

    public static void main(String[] args) {
        YieldDemo01 yieldDemo01 = new YieldDemo01();
        Thread t = new Thread(yieldDemo01);
        t.start();

        for (int i =0; i<1000; i++) {
            if (i % 20 == 0) {
                Thread.yield(); //暂停本线程，main
            }
            System.out.println("main....." + i);
        }
    }

    @Override
    public void run() {
        super.run();
        for (int i=0; i<1000; i++) {
            System.out.println("yield...." + i);
        }
    }
}
